﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="Scripts/jquery-1.8.3.js"></script>
    <script src="Scripts/jqclass.js"></script>
    <script src="Scripts/common.js"></script>
    <script src="Scripts/model.js"></script>
    <title></title>
</head>
<body>

    <div id="divTest" onclick="test()">测试</div>
    <canvas id="mycanvas" width="500" height="500">浏览器不支持HTML5，无法访问当前应用。</canvas>
    <script type="text/javascript">
        var Model = {};
        /*
        数据模型类
        */
        //数据模型类(伪)
        Model.CPoint = jClass({
            _constructor: function (x, y) {
                this.x = x;
                this.y = y;
            },
            x: null,
            y: null
        });

        Model.CKeyPoint = jClass.extend(Model.CPoint, {
            id: null,
            isselected: false,
            shapeid: null
        });

        Model.CShape = jClass({
            id: null
        });
        /*
        逻辑类
        */
        //业务逻辑类(伪)
        var BLL = {};
        BLL.ModelListKeyPoint = {
            getListClass: function (id, arraysou) {
                var _arraykeypoint = new Array();
                for (var i = 0; i < arraysou.length; i++) {
                    if (arraysou[i].shapeid == id) {
                        var _model = new Model.CKeyPoint();
                        _model.x = arraysou[i].x;
                        _model.y = arraysou[i].y;
                        _model.shapeid = arraysou[i].shapeid;
                        _arraykeypoint.push(_model);
                    }
                }
                return _arraykeypoint;
            }
        };

        BLL.CKeyPoint = {
            add: function (model) {
                DAL.add(model);
            },
            getModelList: function (objparameters) {
                var data = DAL.CKeyPoint.getJsonData(objparameters);
                return BLL.CKeyPoint.jsonToArray(data);
            },
            jsonToArray: function (data) {
                var _ayreturn = new Array();
                $.each(data, function (i) {
                    var _model = new Model.CKeyPoint();
                    _model.x = data[i].x;
                    _model.y = data[i].y;
                    _model.id = data[i].id;
                    _model.isselected = data[i].isselected;
                    _model.shapeid = data[i].shapeid;
                    _ayreturn.push(_model);
                });
                return _ayreturn();
            }
        };


        /*
        数据访问层类
       */
        var DAL = {};
        DAL.CKeyPoint = {
            add: function (model) {
                var _strurl = "";
                var _parameters = { x: model.x, y: model.y, id: model.id, shapeid: model.shapeid };
                var _data = JsonDateHelper.add(_strurl, _parameters);
            },
            getJsonData: function (objparameters) {
                var _strurl = "";
                var _jsondata = new Array();
                var data = JsonDateHelper.getJson(_strurl, objparameters);
                return data;
            },
        };


        /*
        JSON数据助手类JsonDataHelper
        */

        JsonDateHelper = {
            getJson: function (url, objparameters) {
                //获取JSON数据
                $.getJSON(
                    url,
                    objparameters,
                    function (data) {
                        return data;
                    }
                    );
            },
            add: function (url, parameters) {
                url,
                parameters,
                function (data) {
                    return data;
                }
            }
        }
        var mycanvas = $("#mycanvas")[0];
        var ctx = mycanvas.getContext("2d");

        function test() {
            JsonDateHelper.add();
            _strjson = "OK";
            JsonDateHelper.add();

        }
    </script>
</body>
</html>
